package com.lg.erp.controller.chenjunhui;


import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.chenjunhui.TOrderC;
import com.lg.erp.entity.chenjunhui.TProductionLine;
import com.lg.erp.entity.maxuejiao.TPrinter;
import com.lg.erp.mapper.chenjunhui.TOrderMapper;
import com.lg.erp.service.chenjunhui.ITOrderService;
import com.lg.erp.service.chenjunhui.ITProductionLineService;
import com.lg.erp.service.impl.chenjunhui.TOrderServiceImpl;
import com.lg.erp.service.maxuejiao.IJGDYService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ligen
 * @since 2021-04-19
 */
@RestController
public class TOrderController {

    @Autowired
    private TOrderServiceImpl tOrderService;
    @Autowired
    private TOrderMapper tOrderMapper;
    @Autowired
    private ITOrderService itOrderService;
    @Autowired
    private ITProductionLineService itProductionLineService;
    @Autowired
    private IJGDYService ijgdyService;

    /**
     * 模糊查询
     * @param inp
     * @return
     */
    @ResponseBody
    @GetMapping("/searchSelect/{inp}/{pageNum}/{pageSize}")
    public JsonResult selectUserRoles(@PathVariable String inp,
                                      @PathVariable Integer pageNum,
                                      @PathVariable Integer pageSize){
        //查询数据数量
        int i = tOrderService.getAllCount(inp);
        //模糊查询
        List<TOrderC> tOrders = tOrderService.getAllTOrderPage(pageNum,pageSize,inp);
        return new JsonResult(1,String.valueOf(i),tOrders);
    }

    /**
     * 分页查询+模糊查询
     * @param pageNum    当前页码
     * @param pageSize   查询的数量
     * @param orderId  订单编号
     * @return
     */
    @RequestMapping("/PageTOrder/{orderId}/{pageNum}/{pageSize}")
    public JsonResult selectPage(@PathVariable String orderId,
                                 @PathVariable Integer pageNum,
                                 @PathVariable Integer pageSize){
        //查询数据数量
        int i = tOrderService.getTOrderCount(orderId);
        //分页查询数据
        List<TOrderC> tOrders=tOrderService.getTOrderPage(pageNum,pageSize,orderId);
        return new JsonResult(1,String.valueOf(i),tOrders);
    }

    /**
     * 查询所有生产产线bb
     * @return
     */
    @GetMapping("/tProductionLines")
    public JsonResult selectTProductionLines(){
        List<TProductionLine> tProductionLines = itProductionLineService.list();
        return new JsonResult(1,"ok",tProductionLines);
    }

    /**
     * 查询所有打印机
     * @return
     */
    @GetMapping("/tPrinters")
    public JsonResult selectTPrinters(){
        List<TPrinter> tPrinters = ijgdyService.list();
        return new JsonResult(1,"ok",tPrinters);
    }

    /**
     * 加入到激光码生产列表
     * @return
     */
    @PostMapping("/addTPrinter")
    public JsonResult addTPrinter(@RequestBody TOrderC tOrderC){
        System.out.println(tOrderC);
        tOrderC.setProductStatus("7");
        itOrderService.modifyTOrderC(tOrderC);
        return new JsonResult(1,"ok",null);
    }

}
